package interview.reverselinkedlist;

import interview.common.LinkedNode;

public class ReverseLinkedList {
	public LinkedNode reverse(LinkedNode root) {
		LinkedNode prev = null;
		LinkedNode current = root;
		
		if(root == null) {
			return null;
		}
		
		LinkedNode next = root.getNext();
		while(next != null) {
			current.setNext(prev);
			prev = current;
			current = next;
			next = next.getNext();
		}
		current.setNext(prev);
		return current;
	}
}
